import wx


class ListBookExample(wx.Frame):
    def __init__(self, parent, title):
        super(ListBookExample, self).__init__(parent,
                                              title=title,
                                              size=(400, 300))
        self.listbook = wx.Listbook(self, style=wx.LB_DEFAULT)
        self.page1 = wx.Panel(self.listbook)
        wx.StaticText(self.page1, label="这是第一个页面 1", pos=(10, 10))
        button1 = wx.Button(self.page1, label="按钮1", pos=(10, 50))
        button1.Bind(wx.EVT_BUTTON, self.on_button1)  # 修正方法名称

        self.page2 = wx.Panel(self.listbook)
        wx.StaticText(self.page2, label="这是第二个页面 2", pos=(10, 10))
        button2 = wx.Button(self.page2, label="按钮2", pos=(10, 50))
        button2.Bind(wx.EVT_BUTTON, self.on_button2)  # 修正方法名称

        # 页面添加到 listbook
        self.listbook.AddPage(self.page1, "页面1")
        self.listbook.AddPage(self.page2, "页面2")

        self.listbook.SetSize(self.GetClientSize())
        # 绑定事件处理器
        self.listbook.Bind(wx.EVT_LISTBOOK_PAGE_CHANGED,
                           self.on_page_changed)

    def on_button1(self, event):
        wx.MessageBox("按钮1被点击了", "信息")

    def on_button2(self, event):
        wx.MessageBox("按钮2被点击了", "信息")

    def on_page_changed(self, event):
        selection = self.listbook.GetSelection()
        wx.MessageBox(f"当前选中的页面是：{selection+1}",
                      "页面更改")


app = wx.App(False)
frame = ListBookExample(None, "ListBook Example")
frame.Show()
app.MainLoop()
